﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GuiLayer
{
    public partial class KpContact : Form
    {
        public KpContact()
        {
            InitializeComponent();

            btnUpload.Enabled = false;
            txtAttachment.Enabled = false;
        }
       
        private void btnSend_Click(object sender, EventArgs e)
        {
            try
            {
                SmtpClient client = new SmtpClient("smtp.gmail.com");
                client.Port = 587;
                client.EnableSsl = true;
                client.Timeout = 100000;
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                client.UseDefaultCredentials = false;
                client.Credentials = new NetworkCredential(
                  "pxlperfecthelp@gmail.com", "pxlperfect123");
                MailMessage msg = new MailMessage();
                String to = "pxlperfecthelp@gmail.com";
                msg.To.Add(to);
                msg.From = new MailAddress(txtEmail.Text);
                msg.Subject = txtSubject.Text;
                msg.Body = txtMessage.Text;
                if (chkAttachment.Checked)
                {
                    Attachment data = new Attachment(txtAttachment.Text);
                    msg.Attachments.Add(data);
                }
                client.Send(msg);
                MessageBox.Show("Successfully Sent Message.");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnUpload_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                txtAttachment.Text = dlg.FileName.ToString();
            }
        }

        private void chkAttachment_CheckedChanged(object sender, EventArgs e)
        {
            if (!chkAttachment.Checked)
            {
                btnUpload.Enabled = false;
                txtAttachment.Enabled = false;
            }
            else
            {
                btnUpload.Enabled = true;
                txtAttachment.Enabled = true;
            }
        }

        private void btnTerug_Click(object sender, EventArgs e)
        {
            this.Hide();
            KpAlgemeen f2 = new KpAlgemeen();
            f2.ShowDialog();
            this.Close();
        }
    }
}
